<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="en">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">
<script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
<link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
<style>
    .pace .pace-progress {
        background: #000000; /*进度条颜色*/
        height: 3px;
    }
    .pace .pace-progress-inner {
         box-shadow: 0 0 10px #1E92FB, 0 0 5px     #1E92FB; /*阴影颜色*/
    }
    .pace .pace-activity {
        border-top-color: #808080;    /*上边框颜色*/
        border-left-color: #808080;    /*左边框颜色*/
    }
</style>



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="CTF," />





  <link rel="alternate" href="/rss2.xml" title="diao-diao-UPUP" type="application/atom+xml" />






<meta name="description" content="Python3基础语法编码默认情况下，Python3源码文件以UTF-O编码，所有的字符串都是unicode字符串。 标识符第一个字符必须是字母或下划线_其他部分由字母，数字和下划线组成大小写敏感 python保留字1&amp;apos;False&amp;apos;, &amp;apos;None&amp;apos;, &amp;apos;True&amp;apos;, &amp;apos;and&amp;apos;, &amp;apos;as&amp;apos;, &amp;apos;assert&amp;apos;, &amp;apos;break&amp;apos;, &amp;apos;class&amp;apos;, &amp;apos;continue&amp;apos;, &amp;apos;def&amp;apos;, &amp;apos;del&amp;apos;,">
<meta name="keywords" content="CTF">
<meta property="og:type" content="article">
<meta property="og:title" content="Python3-2020&#x2F;2&#x2F;22-周报0">
<meta property="og:url" content="http:&#x2F;&#x2F;yoursite.com&#x2F;2020&#x2F;02&#x2F;22&#x2F;Python&#x2F;index.html">
<meta property="og:site_name" content="diao-diao-UPUP">
<meta property="og:description" content="Python3基础语法编码默认情况下，Python3源码文件以UTF-O编码，所有的字符串都是unicode字符串。 标识符第一个字符必须是字母或下划线_其他部分由字母，数字和下划线组成大小写敏感 python保留字1&amp;apos;False&amp;apos;, &amp;apos;None&amp;apos;, &amp;apos;True&amp;apos;, &amp;apos;and&amp;apos;, &amp;apos;as&amp;apos;, &amp;apos;assert&amp;apos;, &amp;apos;break&amp;apos;, &amp;apos;class&amp;apos;, &amp;apos;continue&amp;apos;, &amp;apos;def&amp;apos;, &amp;apos;del&amp;apos;,">
<meta property="og:locale" content="en">
<meta property="og:updated_time" content="2020-02-24T12:09:23.020Z">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2020/02/22/Python/"/>





  <title>Python3-2020/2/22-周报0 | diao-diao-UPUP</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">diao-diao-UPUP</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">我是一只web狗</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Categories
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" target="_blank" rel="noopener" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="Searching..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/02/22/Python/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="51nd0re1">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/header.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="diao-diao-UPUP">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Python3-2020/2/22-周报0</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2020-02-22T10:54:18+08:00">
                2020-02-22
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%97%A5%E5%B8%B8%E5%AD%A6%E4%B9%A0/" itemprop="url" rel="index">
                    <span itemprop="name">日常学习</span>
                  </a>
                </span>

                
                
                  , 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%97%A5%E5%B8%B8%E5%AD%A6%E4%B9%A0/Python3/" itemprop="url" rel="index">
                    <span itemprop="name">Python3</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Python3基础语法"><a href="#Python3基础语法" class="headerlink" title="Python3基础语法"></a>Python3基础语法</h1><h2 id="编码"><a href="#编码" class="headerlink" title="编码"></a>编码</h2><p>默认情况下，Python3源码文件以UTF-O编码，所有的字符串都是unicode字符串。</p>
<h2 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h2><p>第一个字符必须是字母或下划线_<br>其他部分由字母，数字和下划线组成<br>大小写敏感</p>
<h2 id="python保留字"><a href="#python保留字" class="headerlink" title="python保留字"></a>python保留字</h2><figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">'False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'</span><br></pre></td></tr></table></figure>
<h2 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h2><h1 id="为单行注释"><a href="#为单行注释" class="headerlink" title="为单行注释"></a>为单行注释</h1><p>多行注释可以使用多个#，’’’和”””</p>
<h2 id="行与缩进"><a href="#行与缩进" class="headerlink" title="行与缩进"></a>行与缩进</h2><p>由于python的特色，需要分号作为结尾，也不需要{}来表示代码块，所以缩进尤为重要，是python区分不同代码块的重要环节；缩进的空格数可变，同一个代码块必须包含相同的缩进空格数<br>例如：<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="literal">True</span>:</span><br><span class="line">    <span class="keyword">print</span> (<span class="string">"True"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    <span class="keyword">print</span> (<span class="string">"False"</span>)</span><br></pre></td></tr></table></figure></p>
<h2 id="多行语句"><a href="#多行语句" class="headerlink" title="多行语句"></a>多行语句</h2><p>python通常是一行写完，如果语句很长，使用<code>\</code>反斜杠来实现多行语句</p>
<p>在[].{}.()中的多行语句不需要反斜杠</p>
<h2 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h2><p>python有四种数据类型：整型，布尔型，浮点数和复数<br><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">int</span><span class="params">(整型)</span></span>  如<span class="number">1</span></span><br><span class="line"><span class="function"><span class="title">bool</span><span class="params">(布尔)</span></span>  如ture</span><br><span class="line"><span class="function"><span class="title">float</span><span class="params">(浮点数)</span></span>  如<span class="number">1.23</span></span><br><span class="line"><span class="function"><span class="title">complex</span><span class="params">(复数)</span></span>  如<span class="number">1</span>+<span class="number">2</span>j</span><br></pre></td></tr></table></figure></p>
<h2 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h2><p>python中单引号与双引号使用相同</p>
<p>三引号<code>&#39;&#39;&#39;</code>可以指定一个多行字符串</p>
<p>转义符<code>\</code></p>
<p>反斜杠可以转义，使用r可以让反斜杠不发生转义。如r”this is a line with \n” \n会正常显示 而不是换行</p>
<p>按字面意义级联字符串。如”this””is””string”会被自动转换为this is string</p>
<p>字符串可以用+连接，用*重复</p>
<p>python中字符串有两种索引方式，从左开始以0开始，从右开始以-1开始</p>
<p>字符串不可以改变</p>
<p>没有单独的字符类型，一个字符就是长度为1的字符串</p>
<p>字符串截取的语法格式为：<code>变量[头下标:尾下标:步长]</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">str=<span class="string">'Runoob'</span></span><br><span class="line"></span><br><span class="line">print(str)  	<span class="comment">#输出字符串</span></span><br><span class="line">print(str[<span class="number">0</span>:<span class="number">-1</span>]) 	<span class="comment">#输出第一个到倒数第二个的所有字符</span></span><br><span class="line">print(str[<span class="number">0</span>]) 	<span class="comment">#输出第一个字符</span></span><br><span class="line">print(str[<span class="number">2</span>:<span class="number">5</span>]) 	<span class="comment">#输出从第三个开始到第五个的字符</span></span><br><span class="line">print(str + ‘你好’) 	<span class="comment">#连接字符串</span></span><br><span class="line">print(<span class="string">'hello\nrunoob'</span>) 	<span class="comment">#反斜杠转义</span></span><br><span class="line">print(<span class="string">r'hello\nrunoob'</span>) 	<span class="comment">#在字符串前加一个r，不发生转义</span></span><br></pre></td></tr></table></figure>
<h3 id="访问字符串中的值"><a href="#访问字符串中的值" class="headerlink" title="访问字符串中的值"></a>访问字符串中的值</h3><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">var1 = 'Hello World!'</span><br><span class="line">var2 = <span class="string">"Runoob"</span></span><br><span class="line"> </span><br><span class="line">print (<span class="string">"var1[0]: "</span>, var1[0])</span><br><span class="line">print (<span class="string">"var2[1:5]: "</span>, var2[1:5])</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line"><span class="section">var1[0]:  H</span></span><br><span class="line"><span class="section">var2[1:5]:  unoo</span></span><br></pre></td></tr></table></figure>
<h3 id="字符串更新"><a href="#字符串更新" class="headerlink" title="字符串更新"></a>字符串更新</h3><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">var1 = <span class="string">'Hello World!'</span></span><br><span class="line"> </span><br><span class="line"><span class="builtin-name">print</span> (<span class="string">"已更新字符串 : "</span>, var1[:6] + <span class="string">'Runoob!'</span>)</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">已更新字符串 :  Hello Runoob!</span><br></pre></td></tr></table></figure>
<h3 id="字符串运算符"><a href="#字符串运算符" class="headerlink" title="字符串运算符"></a>字符串运算符</h3><figure class="highlight brainfuck"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="literal">+</span><span class="comment">	字符串连接	a</span> <span class="literal">+</span> <span class="comment">b</span> <span class="comment">输出结果：</span> <span class="comment">HelloPython</span></span><br><span class="line"><span class="comment">*	重复输出字符串	a*2</span> <span class="comment">输出结果：HelloHello</span></span><br><span class="line"><span class="comment"></span><span class="title">[</span><span class="title">]</span><span class="comment">	通过索引获取字符串中字符	a</span><span class="title">[</span><span class="comment">1</span><span class="title">]</span> <span class="comment">输出结果</span> <span class="comment">e</span></span><br></pre></td></tr></table></figure>
<p>例如：<br><figure class="highlight livecodeserver"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">a</span> = <span class="string">"Hello"</span></span><br><span class="line">b = <span class="string">"Python"</span></span><br><span class="line"> </span><br><span class="line">print(<span class="string">"a + b 输出结果："</span>, <span class="keyword">a</span> + b)</span><br><span class="line">print(<span class="string">"a * 2 输出结果："</span>, <span class="keyword">a</span> * <span class="number">2</span>)</span><br><span class="line">print(<span class="string">"a[1] 输出结果："</span>, <span class="keyword">a</span>[<span class="number">1</span>])</span><br><span class="line">print(<span class="string">"a[1:4] 输出结果："</span>, <span class="keyword">a</span>[<span class="number">1</span>:<span class="number">4</span>])</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line"><span class="keyword">a</span> + b 输出结果： HelloPython</span><br><span class="line"><span class="keyword">a</span> * <span class="number">2</span> 输出结果： HelloHello</span><br><span class="line"><span class="keyword">a</span>[<span class="number">1</span>] 输出结果： e</span><br><span class="line"><span class="keyword">a</span>[<span class="number">1</span>:<span class="number">4</span>] 输出结果： ell</span><br></pre></td></tr></table></figure></p>
<h3 id="三引号"><a href="#三引号" class="headerlink" title="三引号"></a>三引号</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">para_str = <span class="string">"""这是一个多行字符串的实例</span></span><br><span class="line"><span class="string">多行字符串可以使用制表符</span></span><br><span class="line"><span class="string">TAB ( \t )。</span></span><br><span class="line"><span class="string">也可以使用换行符 [ \n ]。</span></span><br><span class="line"><span class="string">"""</span></span><br><span class="line"><span class="keyword">print</span> (para_str</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">这是一个多行字符串的实例</span><br><span class="line">多行字符串可以使用制表符</span><br><span class="line">TAB (    )。</span><br><span class="line">也可以使用换行符 [ </span><br><span class="line"> ]。</span><br></pre></td></tr></table></figure>
<h3 id="常用字符串函数"><a href="#常用字符串函数" class="headerlink" title="常用字符串函数"></a>常用字符串函数</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">capitalize()  第一个字符转大写</span><br><span class="line"></span><br><span class="line">center(width,fillchar)  指定一个宽度width居中的字符串，fillchar位填充的字符，默认为空格</span><br><span class="line"></span><br><span class="line">count(str,beg=0,<span class="keyword">end</span>=<span class="keyword">len</span>(<span class="keyword">string</span>))  返回<span class="keyword">str</span>在<span class="keyword">string</span>中出现的次数，beg和<span class="keyword">end</span>可以指定范围</span><br><span class="line"></span><br><span class="line"><span class="keyword">encode</span>(<span class="keyword">encoding</span>=<span class="string">'UTF-8'</span>,<span class="keyword">errors</span>=<span class="string">'strict'</span>)  以<span class="keyword">encoding</span>指定的编码格式编码字符串</span><br><span class="line"></span><br><span class="line">find(<span class="keyword">str</span>,beg=<span class="number">0</span>,<span class="keyword">end</span>=<span class="keyword">len</span>(<span class="keyword">string</span>))  查找<span class="keyword">str</span>字符是否在<span class="keyword">string</span>中，beg和<span class="keyword">end</span>指定范围</span><br><span class="line"></span><br><span class="line"><span class="keyword">upper</span>()  小写转大写</span><br><span class="line"></span><br><span class="line"><span class="keyword">lower</span>()  大写转小写</span><br><span class="line"></span><br><span class="line">swapcase()  将字符串中大写转换为小写，小写转换为大写</span><br><span class="line"></span><br><span class="line">islower()  如果字符串中包含至少一个区分大小写的字符，并且所有这些(区分大小写的)字符都是小写，则返回 <span class="literal">True</span>，否则返回 <span class="literal">False</span></span><br><span class="line">isupper()  类似</span><br><span class="line"></span><br><span class="line"><span class="keyword">len</span>()  返回字符串长度</span><br><span class="line"></span><br><span class="line"><span class="keyword">max</span>(<span class="keyword">str</span>)  返回最大值</span><br><span class="line"><span class="keyword">min</span>类似</span><br><span class="line"></span><br><span class="line"><span class="keyword">replace</span>(<span class="keyword">old</span>,<span class="keyword">new</span>[,<span class="keyword">max</span>])  把字符串中的str1转换成str2，如果<span class="keyword">max</span>指定，替换不超过<span class="keyword">max</span>次</span><br><span class="line"></span><br><span class="line"><span class="keyword">split</span>(<span class="keyword">str</span><span class="string">""</span>,<span class="keyword">num</span>=string.count(<span class="keyword">str</span>))  以<span class="keyword">str</span>为分隔符截取字符串</span><br></pre></td></tr></table></figure>
<h2 id="列表"><a href="#列表" class="headerlink" title="列表"></a>列表</h2><p>类似于一个数组</p>
<h3 id="访问列表中的值"><a href="#访问列表中的值" class="headerlink" title="访问列表中的值"></a>访问列表中的值</h3><figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">list1 = [<span class="string">'Google'</span>, <span class="string">'Runoob'</span>, <span class="number">1997</span>, <span class="number">2000</span>];</span><br><span class="line">list2 = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span> ];</span><br><span class="line"> </span><br><span class="line">print (<span class="string">"list1[0]: "</span>, list1[<span class="number">0</span>])</span><br><span class="line">print (<span class="string">"list2[1:5]: "</span>, list2[<span class="number">1</span>:<span class="number">5</span>])</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">list1[<span class="number">0</span>]:  Google</span><br><span class="line">list2[<span class="number">1</span>:<span class="number">5</span>]:  [<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>]</span><br></pre></td></tr></table></figure>
<h3 id="删除列表元素"><a href="#删除列表元素" class="headerlink" title="删除列表元素"></a>删除列表元素</h3><figure class="highlight livescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">list</span> = [<span class="string">'Google'</span>, <span class="string">'Runoob'</span>, <span class="number">1997</span>, <span class="number">2000</span>]</span><br><span class="line"> </span><br><span class="line"><span class="built_in">print</span> (<span class="string">"原始列表 : "</span>, <span class="keyword">list</span>)</span><br><span class="line">del <span class="keyword">list</span>[<span class="number">2</span>]</span><br><span class="line"><span class="built_in">print</span> (<span class="string">"删除第三个元素 : "</span>, <span class="keyword">list</span>)</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">原始列表 :  [<span class="string">'Google'</span>, <span class="string">'Runoob'</span>, <span class="number">1997</span>, <span class="number">2000</span>]</span><br><span class="line">删除第三个元素 :  [<span class="string">'Google'</span>, <span class="string">'Runoob'</span>, <span class="number">2000</span>]</span><br></pre></td></tr></table></figure>
<h3 id="列表脚本操作符"><a href="#列表脚本操作符" class="headerlink" title="列表脚本操作符"></a>列表脚本操作符</h3><figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">len([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])   结果为<span class="number">3</span> 显示列表的长度</span><br><span class="line"></span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]+[<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>]  结果为[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>] 组合</span><br><span class="line"></span><br><span class="line">[<span class="string">'hi'</span>]*<span class="number">4</span>   结果为[<span class="string">'Hi!'</span>, <span class="string">'Hi!'</span>, <span class="string">'Hi!'</span>, <span class="string">'Hi!'</span>] 重复</span><br><span class="line"></span><br><span class="line"><span class="number">3</span> <span class="keyword">in</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]   结果为True  元素是否存在于列表中</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> x <span class="keyword">in</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]: print(x, end=<span class="string">" "</span>)   结果为<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>  迭代</span><br></pre></td></tr></table></figure>
<h3 id="列表常用函数"><a href="#列表常用函数" class="headerlink" title="列表常用函数"></a>列表常用函数</h3><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">len</span><span class="params">(list)</span></span>  列表元素个数</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">max</span><span class="params">(list)</span></span>  返回列表元素最大值</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">min</span><span class="params">(list)</span></span>  返回列表元素最小值</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">list</span><span class="params">(seq)</span></span>  将元组转换为列表</span><br></pre></td></tr></table></figure>
<h3 id="列表常用方法"><a href="#列表常用方法" class="headerlink" title="列表常用方法"></a>列表常用方法</h3><figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">list</span>.<span class="keyword">append</span>(obj)  在末尾添加新的对象</span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>.<span class="built_in">count</span>(obj)  统计某个元素出现的个数</span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>.<span class="built_in">extend</span>(seq)  在列表末尾一次性追加另一个序列中的多个值</span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>.<span class="keyword">insert</span>(<span class="built_in">index</span>,obj)  将对象插入列表</span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>.<span class="built_in">remove</span>(obj)  移除列表中某个值的第一个匹配项</span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>.<span class="keyword">pop</span>([<span class="built_in">index</span>=-<span class="number">1</span>])  移除列表中的一个元素，并且返回该元素</span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>.<span class="keyword">sort</span>(key=None,<span class="built_in">reverse</span>=False)  对列表进行排序</span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>.clear()  清空列表</span><br></pre></td></tr></table></figure>
<h2 id="元组"><a href="#元组" class="headerlink" title="元组"></a>元组</h2><p>Python 的元组与列表类似，不同之处在于元组的元素不能修改</p>
<p>元组使用小括号，列表使用方括号</p>
<p>元组创建很简单，只需要在括号中添加元素，并使用逗号隔开即可</p>
<p>元组是不可变的</p>
<h3 id="访问元组"><a href="#访问元组" class="headerlink" title="访问元组"></a>访问元组</h3><figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">tup1 = (<span class="string">'Google'</span>, <span class="string">'Runoob'</span>, <span class="number">1997</span>, <span class="number">2000</span>)</span><br><span class="line">tup2 = (<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span> )</span><br><span class="line"> </span><br><span class="line">print (<span class="string">"tup1[0]: "</span>, tup1[<span class="number">0</span>])</span><br><span class="line">print (<span class="string">"tup2[1:5]: "</span>, tup2[<span class="number">1</span>:<span class="number">5</span>])</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">tup1[<span class="number">0</span>]:  Google</span><br><span class="line">tup2[<span class="number">1</span>:<span class="number">5</span>]:  (<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>)</span><br></pre></td></tr></table></figure>
<h3 id="删除元组"><a href="#删除元组" class="headerlink" title="删除元组"></a>删除元组</h3><figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">tup = (<span class="string">'Google'</span>, <span class="string">'Runoob'</span>, <span class="number">1997</span>, <span class="number">2000</span>)</span><br><span class="line"> </span><br><span class="line"><span class="keyword">print</span> (tup)</span><br><span class="line">del tup</span><br><span class="line"><span class="keyword">print</span> (<span class="string">"删除后的元组 tup : "</span>)</span><br><span class="line"><span class="keyword">print</span> (tup)</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">删除后的元组 tup : </span><br><span class="line">Traceback (most recent <span class="keyword">call</span> <span class="keyword">last</span>):</span><br><span class="line">  File <span class="string">"test.py"</span>, <span class="built_in">line</span> <span class="number">8</span>, in <span class="symbol">&lt;module&gt;</span></span><br><span class="line">    <span class="keyword">print</span> (tup)</span><br><span class="line">NameError: name <span class="string">'tup'</span> <span class="keyword">is</span> not defined</span><br></pre></td></tr></table></figure>
<h3 id="元组运算符"><a href="#元组运算符" class="headerlink" title="元组运算符"></a>元组运算符</h3><p>与列表几乎一致</p>
<h3 id="元组常用函数"><a href="#元组常用函数" class="headerlink" title="元组常用函数"></a>元组常用函数</h3><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">tuple</span><span class="params">(iterable)</span></span>  将可迭代系列转换为元组</span><br><span class="line"></span><br><span class="line">其余函数与列表相同</span><br></pre></td></tr></table></figure>
<h2 id="字典"><a href="#字典" class="headerlink" title="字典"></a>字典</h2><p>字典是另一种可变容器模型，且可存储任意类型对象。</p>
<p>字典的每个键值(key=&gt;value)对用冒号(:)分割，每个对之间用逗号(,)分割，整个字典包括在花括号({})中</p>
<h3 id="访问字典里的值"><a href="#访问字典里的值" class="headerlink" title="访问字典里的值"></a>访问字典里的值</h3><figure class="highlight prolog"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">dict = &#123;<span class="string">'Name'</span>: <span class="string">'Runoob'</span>, <span class="string">'Age'</span>: <span class="number">7</span>, <span class="string">'Class'</span>: <span class="string">'First'</span>&#125;</span><br><span class="line"> </span><br><span class="line">print (<span class="string">"dict['Name']: "</span>, dict[<span class="string">'Name'</span>])</span><br><span class="line">print (<span class="string">"dict['Age']: "</span>, dict[<span class="string">'Age'</span>])</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">dict[<span class="string">'Name'</span>]:  <span class="symbol">Runoob</span></span><br><span class="line">dict[<span class="string">'Age'</span>]:  <span class="number">7</span></span><br></pre></td></tr></table></figure>
<h3 id="删除字典元素"><a href="#删除字典元素" class="headerlink" title="删除字典元素"></a>删除字典元素</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">dict = &#123;<span class="string">'Name'</span>: <span class="string">'Runoob'</span>, <span class="string">'Age'</span>: <span class="number">7</span>, <span class="string">'Class'</span>: <span class="string">'First'</span>&#125;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">del</span> dict[<span class="string">'Name'</span>] <span class="comment"># 删除键 'Name'</span></span><br><span class="line">dict.clear()     <span class="comment"># 清空字典</span></span><br><span class="line"><span class="keyword">del</span> dict         <span class="comment"># 删除字典</span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">print</span> (<span class="string">"dict['Age']: "</span>, dict[<span class="string">'Age'</span>])</span><br><span class="line"><span class="keyword">print</span> (<span class="string">"dict['School']: "</span>, dict[<span class="string">'School'</span>])</span><br><span class="line"></span><br><span class="line">结果为：</span><br><span class="line">Traceback (most recent call last):</span><br><span class="line">  File <span class="string">"test.py"</span>, line <span class="number">9</span>, <span class="keyword">in</span> &lt;module&gt;</span><br><span class="line">    <span class="keyword">print</span> (<span class="string">"dict['Age']: "</span>, dict[<span class="string">'Age'</span>])</span><br><span class="line">TypeError: <span class="string">'type'</span> object <span class="keyword">is</span> <span class="keyword">not</span> subscriptable</span><br></pre></td></tr></table></figure>
<h3 id="字典键的特性"><a href="#字典键的特性" class="headerlink" title="字典键的特性"></a>字典键的特性</h3><p>1）不允许同一个键出现两次。创建时如果同一个键被赋值两次，后一个值会被记住</p>
<p>2）键必须不可变，所以可以用数字，字符串或元组充当，而用列表就不行</p>
<h3 id="字典常用函数"><a href="#字典常用函数" class="headerlink" title="字典常用函数"></a>字典常用函数</h3><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">len</span><span class="params">(dict)</span></span>  计算字典元素个数，即键的总数</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">str</span><span class="params">(dict)</span></span>  输出字典，以可打印的字符串表示</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">type</span><span class="params">(variable)</span></span>  返回输入的变量类型，如果变量是字典就返回字典类型</span><br></pre></td></tr></table></figure>
<h3 id="字典常用方法"><a href="#字典常用方法" class="headerlink" title="字典常用方法"></a>字典常用方法</h3><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">radiansdict</span><span class="selector-class">.clear</span>()  删除字典内所有元素</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">radiansdict</span><span class="selector-class">.get</span>(key, default=None)  返回指定键的值，如果值不在字典中返回<span class="selector-tag">default</span>值</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">radiansdict</span><span class="selector-class">.items</span>()  以列表返回可遍历的(键, 值) 元组数组</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">radiansdict</span><span class="selector-class">.values</span>()  返回一个迭代器，可以使用 <span class="selector-tag">list</span>() 来转换为列表</span><br></pre></td></tr></table></figure>
<h2 id="用户输入"><a href="#用户输入" class="headerlink" title="用户输入"></a>用户输入</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">input(<span class="string">"\n\n按下enter键后退出"</span>)</span><br></pre></td></tr></table></figure>
<h2 id="同一行显示多条语句"><a href="#同一行显示多条语句" class="headerlink" title="同一行显示多条语句"></a>同一行显示多条语句</h2><p>语句之间必须用分号分隔</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sys;x=<span class="string">'runoob'</span>;sys.stdout.write(x+<span class="string">'\n'</span>)</span><br></pre></td></tr></table></figure>
<p>输出结果为：<br><figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">runoob</span></span><br></pre></td></tr></table></figure></p>
<h2 id="多个语句构成代码组"><a href="#多个语句构成代码组" class="headerlink" title="多个语句构成代码组"></a>多个语句构成代码组</h2><p>像if,while,de和class这样的复合语句，首行以关键字开始，以冒号结束<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> expression : </span><br><span class="line">   suite</span><br><span class="line"><span class="keyword">elif</span> expression : </span><br><span class="line">   suite </span><br><span class="line"><span class="keyword">else</span> : </span><br><span class="line">   suite</span><br></pre></td></tr></table></figure></p>
<h2 id="print-输出"><a href="#print-输出" class="headerlink" title="print 输出"></a>print 输出</h2><p>默认换行，不需要换行在变量尾部加上end=””<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">x=<span class="string">"a"</span></span><br><span class="line">y=<span class="string">"b"</span></span><br><span class="line"><span class="comment"># 换行输出</span></span><br><span class="line">print( x )</span><br><span class="line">print( y )</span><br><span class="line"> </span><br><span class="line">print(<span class="string">'---------'</span>)</span><br><span class="line"><span class="comment"># 不换行输出</span></span><br><span class="line">print( x, end=<span class="string">" "</span> )</span><br><span class="line">print( y, end=<span class="string">" "</span> )</span><br><span class="line">print()</span><br></pre></td></tr></table></figure><br>执行结果为：<br><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">a</span><br><span class="line">b</span><br><span class="line">---------</span><br><span class="line">a b</span><br></pre></td></tr></table></figure></p>
<h2 id="import与from…import"><a href="#import与from…import" class="headerlink" title="import与from…import"></a>import与from…import</h2><p>在 python 用 import 或者 from…import 来导入相应的模块<br>将某个模块中的全部函数导入，格式为： from somemodule import *</p>
<p>导入sys模块<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line">print(<span class="string">'================Python import mode=========================='</span>)</span><br><span class="line"><span class="keyword">print</span> (<span class="string">'命令行参数为:'</span>)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> sys.argv:</span><br><span class="line">    <span class="keyword">print</span> (i)</span><br><span class="line"><span class="keyword">print</span> (<span class="string">'\n python 路径为'</span>,sys.path)</span><br></pre></td></tr></table></figure></p>
<h2 id="命令行参数"><a href="#命令行参数" class="headerlink" title="命令行参数"></a>命令行参数</h2><p>Python -h查看帮助</p>
<h2 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h2><p>运算符分为算数运算符，比较运算符，赋值运算符，逻辑运算符，位运算符，成员运算符，身份运算符</p>
<h3 id="算数运算符"><a href="#算数运算符" class="headerlink" title="算数运算符"></a>算数运算符</h3><figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">以下假设变量a为<span class="number">10</span>，变量b为<span class="number">21</span>:</span><br><span class="line"></span><br><span class="line">+	加 - 两个对象相加	a + b 输出结果 <span class="number">31</span></span><br><span class="line">-	减 - 得到负数或是一个数减去另一个数	a - b 输出结果 <span class="number">-11</span></span><br><span class="line">*	乘 - 两个数相乘或是返回一个被重复若干次的字符串	a * b 输出结果 <span class="number">210</span></span><br><span class="line">/	除 - x 除以 y	b / a 输出结果 <span class="number">2.1</span></span><br><span class="line">%	取模 - 返回除法的余数	b % a 输出结果 <span class="number">1</span></span><br><span class="line">**	幂 - 返回x的y次幂	a**b 为<span class="number">10</span>的<span class="number">21</span>次方</span><br><span class="line"><span class="comment">//	取整除 - 向下取接近除数的整数 9//2=4</span></span><br></pre></td></tr></table></figure>
<h3 id="比较运算符"><a href="#比较运算符" class="headerlink" title="比较运算符"></a>比较运算符</h3><figure class="highlight gcode"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">以下假设变量a为<span class="number">10</span>，变量b为<span class="number">20</span>：</span><br><span class="line"></span><br><span class="line">==	等于 - 比较对象是否相等	<span class="comment">(a == b)</span> 返回 False。</span><br><span class="line">!=	不等于 - 比较两个对象是否不相等	<span class="comment">(a != b)</span> 返回 True。</span><br><span class="line">&gt;	大于 - 返回x是否大于y	<span class="comment">(a &gt; b)</span> 返回 False。</span><br><span class="line">&lt;	小于 - 返回x是否小于y。所有比较运算符返回<span class="number">1</span>表示真，返回<span class="number">0</span>表示假.	<span class="comment">(a &lt; b)</span> 返回 True。</span><br><span class="line">&gt;=	大于等于 - 返回x是否大于等于y。	<span class="comment">(a &gt;= b)</span> 返回 False。</span><br><span class="line">&lt;=	小于等于 - 返回x是否小于等于y。	<span class="comment">(a &lt;= b)</span> 返回 True。</span><br></pre></td></tr></table></figure>
<h3 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h3><figure class="highlight llvm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">以下假设变量a为<span class="number">10</span>，变量b为<span class="number">20</span>：</span><br><span class="line"></span><br><span class="line">=	简单的赋值运算符	<span class="keyword">c</span> = a + b 将 a + b 的运算结果赋值为 <span class="keyword">c</span></span><br><span class="line">+=	加法赋值运算符	<span class="keyword">c</span> += a 等效于 <span class="keyword">c</span> = <span class="keyword">c</span> + a</span><br><span class="line">-=	减法赋值运算符	<span class="keyword">c</span> -= a 等效于 <span class="keyword">c</span> = <span class="keyword">c</span> - a</span><br><span class="line">*=	乘法赋值运算符	<span class="keyword">c</span> *= a 等效于 <span class="keyword">c</span> = <span class="keyword">c</span> * a</span><br><span class="line">/=	除法赋值运算符	<span class="keyword">c</span> /= a 等效于 <span class="keyword">c</span> = <span class="keyword">c</span> / a</span><br><span class="line">%=	取模赋值运算符	<span class="keyword">c</span> %= a 等效于 <span class="keyword">c</span> = <span class="keyword">c</span> % a</span><br><span class="line">**=	幂赋值运算符	<span class="keyword">c</span> **= a 等效于 <span class="keyword">c</span> = <span class="keyword">c</span> ** a</span><br><span class="line">//=	取整除赋值运算符	<span class="keyword">c</span> //= a 等效于 <span class="keyword">c</span> = <span class="keyword">c</span> // a</span><br></pre></td></tr></table></figure>
<h3 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</h3><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&amp;	 按位与运算符：参与运算的两个值,如果两个相应位都为<span class="number">1</span>,则该位的结果为<span class="number">1</span>,否则为<span class="number">0</span>（a &amp; b) 输出结果 <span class="number">12</span></span><br><span class="line">|	 按位或运算符：只要对应的二个二进位有一个为<span class="number">1</span>时，结果位就为<span class="number">1</span>。(a | b) 输出结果 <span class="number">61</span></span><br><span class="line">^	 按位异或运算符：当两对应的二进位相异时，结果为<span class="number">1</span>(a ^ b) 输出结果 <span class="number">49</span></span><br><span class="line">~	 按位取反运算符：对数据的每个二进制位取反,即把<span class="number">1</span>变为<span class="number">0</span>,把<span class="number">0</span>变为<span class="number">1</span>。在一个有符号二进制数的补码形式。</span><br><span class="line">&lt;&lt;	 左移动运算符：运算数的各二进位全部左移若干位，由<span class="string">"&lt;&lt;"</span>右边的数指定移动的位数，高位丢弃，低位补<span class="number">0</span>。a &lt;&lt; <span class="number">2</span> 输出结果 <span class="number">240</span></span><br><span class="line">&gt;&gt;	 右移动运算符：把<span class="string">"&gt;&gt;"</span>左边的运算数的各二进位全部右移若干位，<span class="string">"&gt;&gt;"</span>右边的数指定移动的位数	a &gt;&gt; <span class="number">2</span> 输出结果 <span class="number">15</span></span><br></pre></td></tr></table></figure>
<h3 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">假设变量</span> <span class="string">a</span> <span class="string">为</span> <span class="number">10</span><span class="string">,</span> <span class="string">b为</span> <span class="attr">20:</span></span><br><span class="line"><span class="string">and</span>	<span class="string">x</span> <span class="string">and</span> <span class="string">y</span>	<span class="string">布尔"与"</span> <span class="bullet">-</span> <span class="string">如果</span> <span class="string">x</span> <span class="string">为</span> <span class="literal">False</span><span class="string">，x</span> <span class="string">and</span> <span class="string">y</span> <span class="string">返回</span> <span class="literal">False</span><span class="string">，否则它返回</span> <span class="string">y</span> <span class="string">的计算值。(a</span> <span class="string">and</span> <span class="string">b)</span> <span class="string">返回</span> <span class="number">20</span><span class="string">。</span></span><br><span class="line"><span class="string">or</span>	<span class="string">x</span> <span class="string">or</span> <span class="string">y</span>	<span class="string">布尔"或"</span> <span class="bullet">-</span> <span class="string">如果</span> <span class="string">x</span> <span class="string">是</span> <span class="literal">True</span><span class="string">，它返回</span> <span class="string">x</span> <span class="string">的值，否则它返回</span> <span class="string">y</span> <span class="string">的计算值。(a</span> <span class="string">or</span> <span class="string">b)</span> <span class="string">返回</span> <span class="number">10</span><span class="string">。</span></span><br><span class="line"><span class="string">not</span>	<span class="string">not</span> <span class="string">x</span>	<span class="string">布尔"非"</span> <span class="bullet">-</span> <span class="string">如果</span> <span class="string">x</span> <span class="string">为</span> <span class="literal">True</span><span class="string">，返回</span> <span class="literal">False</span> <span class="string">。如果</span> <span class="string">x</span> <span class="string">为</span> <span class="literal">False</span><span class="string">，它返回</span> <span class="literal">True</span><span class="string">。</span>	</span><br><span class="line">				<span class="string">not(a</span> <span class="string">and</span> <span class="string">b)</span> <span class="string">返回</span> <span class="literal">False</span></span><br></pre></td></tr></table></figure>
<p>例如：<br><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">a = 0</span><br><span class="line">b = 20</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> ( a <span class="keyword">and</span> b ):</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"1 - 变量 a 和 b 都为 true"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"1 - 变量 a 和 b 有一个不为 true"</span>)</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> ( a <span class="keyword">or</span> b ):</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"2 - 变量 a 和 b 都为 true，或其中一个变量为 true"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"2 - 变量 a 和 b 都不为 true"</span>)</span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line">结果为：</span><br><span class="line">1 - 变量 a 和 b 有一个不为 <span class="literal">true</span></span><br><span class="line">2 - 变量 a 和 b 都为 <span class="literal">true</span>，或其中一个变量为 <span class="literal">true</span></span><br></pre></td></tr></table></figure></p>
<h3 id="成员运算符"><a href="#成员运算符" class="headerlink" title="成员运算符"></a>成员运算符</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">in</span>	<span class="string">如果在指定的序列中找到值返回</span> <span class="literal">True</span><span class="string">，否则返回</span> <span class="literal">False</span><span class="string">。</span>	<span class="string">x</span> <span class="string">在</span> <span class="string">y</span> <span class="string">序列中</span> <span class="string">,</span> <span class="string">如果</span> <span class="string">x</span> <span class="string">在</span> <span class="string">y</span> <span class="string">序列中返回</span> <span class="literal">True</span><span class="string">。</span></span><br><span class="line"></span><br><span class="line"><span class="string">not</span> <span class="string">in</span>	<span class="string">如果在指定的序列中没有找到值返回</span> <span class="literal">True</span><span class="string">，否则返回</span> <span class="literal">False</span><span class="string">。</span>	<span class="string">x</span> <span class="string">不在</span> <span class="string">y</span> <span class="string">序列中</span> <span class="string">,</span> <span class="string">如果</span> <span class="string">x</span> <span class="string">不在</span> <span class="string">y</span> <span class="string">序列中返回</span> <span class="literal">True</span><span class="string">。</span></span><br></pre></td></tr></table></figure>
<p>例如：<br><figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">a = <span class="number">2</span></span><br><span class="line">b = <span class="number">20</span></span><br><span class="line"><span class="built_in">list</span> = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span> ];</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> ( a in <span class="built_in">list</span> ):</span><br><span class="line">   <span class="built_in">print</span> (<span class="string">"1 - 变量 a 在给定的列表中 list 中"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">   <span class="built_in">print</span> (<span class="string">"1 - 变量 a 不在给定的列表中 list 中"</span>)</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> ( b <span class="keyword">not</span> in <span class="built_in">list</span> ):</span><br><span class="line">   <span class="built_in">print</span> (<span class="string">"2 - 变量 b 不在给定的列表中 list 中"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">   <span class="built_in">print</span> (<span class="string">"2 - 变量 b 在给定的列表中 list 中"</span>)</span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line">结果为：</span><br><span class="line"><span class="number">1</span> - 变量 a 在给定的列表中 <span class="built_in">list</span> 中</span><br><span class="line"><span class="number">2</span> - 变量 b 不在给定的列表中 <span class="built_in">list</span> 中</span><br></pre></td></tr></table></figure></p>
<h3 id="身份运算符"><a href="#身份运算符" class="headerlink" title="身份运算符"></a>身份运算符</h3><figure class="highlight xquery"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="literal">is</span>	<span class="literal">is</span> 是判断两个标识符是不是引用自一个对象	x <span class="literal">is</span> y, 类似<span class="built_in"> id</span>(x) ==<span class="built_in"> id</span>(y) , 如果引用的是同一个对象则返回 True，否则返回 False</span><br><span class="line"></span><br><span class="line"><span class="literal">is</span><span class="built_in"> not</span>	<span class="literal">is</span><span class="built_in"> not</span> 是判断两个标识符是不是引用自不同对象	x <span class="literal">is</span><span class="built_in"> not</span> y ， 类似<span class="built_in"> id</span>(a) !=<span class="built_in"> id</span>(b)。如果引用的不是同一个对象则返回结果 True，否则返回 False。</span><br></pre></td></tr></table></figure>
<p>例如：<br><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">a = 20</span><br><span class="line">b = 30</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> ( a is b ):</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"1 - a 和 b 有相同的标识"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"1 - a 和 b 没有相同的标识"</span>)</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> ( id(a) == id(b) ):</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"2 - a 和 b 有相同的标识"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">   <span class="builtin-name">print</span> (<span class="string">"2 - a 和 b 没有相同的标识"</span>)</span><br><span class="line">   </span><br><span class="line">结果为：</span><br><span class="line">1 - a 和 b 没有相同的标识</span><br><span class="line">2 - a 和 b 没有相同的标识</span><br></pre></td></tr></table></figure></p>
<h3 id="常用数学函数"><a href="#常用数学函数" class="headerlink" title="常用数学函数"></a>常用数学函数</h3><figure class="highlight gml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">abs</span>(<span class="symbol">x</span>)  返回数字的绝对值 如<span class="built_in">abs</span>(<span class="number">-10</span>) 返回 <span class="number">10</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">ceil</span>(<span class="symbol">x</span>)  向上取整 如math.<span class="built_in">ceil</span>(<span class="number">4.1</span>) 返回 <span class="number">5</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">floor</span>(<span class="symbol">x</span>)  向下取整 如math.<span class="built_in">floor</span>(<span class="number">4.9</span>)返回 <span class="number">4</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">exp</span>(<span class="symbol">x</span>)  返回e的<span class="symbol">x</span>次幂(ex) 如math.<span class="built_in">exp</span>(<span class="number">1</span>) 返回<span class="number">2.718281828459045</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">sqrt</span>(<span class="symbol">x</span>)  求平方根</span><br><span class="line"></span><br><span class="line">acos(<span class="symbol">x</span>)  返回<span class="symbol">x</span>的反余弦弧度值</span><br><span class="line"></span><br><span class="line"><span class="built_in">cos</span>(<span class="symbol">x</span>)  返回<span class="symbol">x</span>的弧度的余弦值</span><br><span class="line"></span><br><span class="line"><span class="built_in">sin</span>,<span class="built_in">tan</span>类似</span><br></pre></td></tr></table></figure>
<h3 id="常用随机数函数"><a href="#常用随机数函数" class="headerlink" title="常用随机数函数"></a>常用随机数函数</h3><figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">choice(seq)  从序列元素中随机挑选一个元素 比如random.choice(range(<span class="number">10</span>))，从<span class="number">0</span>到<span class="number">9</span>中随机挑选一个整数</span><br><span class="line"></span><br><span class="line">random() 随机生成一个实数，在范围[<span class="number">0</span>,<span class="number">1</span>)内</span><br><span class="line"></span><br><span class="line">randrange ([start,] stop [,step])  从指定范围内 按指定基数递增的集合中获取一个随机数 基数默认值为 <span class="number">1</span></span><br></pre></td></tr></table></figure>
<h3 id="数学常量"><a href="#数学常量" class="headerlink" title="数学常量"></a>数学常量</h3><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="literal">pi</span> 数学常量<span class="literal">pi</span> 圆周率</span><br><span class="line">e  数学常量e 自然常数</span><br></pre></td></tr></table></figure>
<h2 id="周报总结："><a href="#周报总结：" class="headerlink" title="周报总结："></a>周报总结：</h2><p> <strong>1.python语言较为简单，但是也面临着一个新的问题，由于python不需要用<code>;</code>来代表语句结束，<code>{}</code>代表代码块，而是使用TAB和空格来进行区分，所以要严格控制TAB和空格的数量，以便区分每个语句或代码块</strong></p>
<p> <strong>2.<code>if while</code>这些复合语句，不像C或者JAVA一样有{}，需要在if [条件] 之后加<code>:</code>表示代码块的开始</strong></p>
<p> <strong>3.<code>import</code>是导入整个模块，<code>from...import</code>是导入某个模块中的某个函数，第二种更为灵活，可以减少时间复杂度，提高效率和辨识度</strong></p>
<p> <strong>4.输入和输出都较为简单，<code>input</code>和<code>print</code>与python2的区别就是需要加括号而不是空格</strong></p>
<p> <strong>5.字符串可以实现多行代码但是需要用三引号括住</strong></p>
<p> <strong>6.字符串不可更改</strong></p>
<p> <strong>7.python对大小写敏感</strong></p>
<p> <strong>8.反斜杠在python中需要慎用，有可能会造成转义而形成不必要的麻烦</strong></p>
<p> <strong>9.python引入了成员运算符<code>（in 和 not in）</code> 可以更加方便地对数据进行查找</strong></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/CTF/" rel="tag"># CTF</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/02/17/BUUCTF-%E6%9E%81%E5%AE%A2%E5%A4%A7%E6%8C%91%E6%88%98-2019-Upload/" rel="next" title="BUUCTF-极客大挑战 2019 Upload">
                <i class="fa fa-chevron-left"></i> BUUCTF-极客大挑战 2019 Upload
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/03/01/Python3-2020-3-1-%E5%91%A8%E6%8A%A51/" rel="prev" title="Python3-2020/3/1-周报1">
                Python3-2020/3/1-周报1 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/header.jpg"
                alt="51nd0re1" />
            
              <p class="site-author-name" itemprop="name">51nd0re1</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/rss2.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/diao-diao" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:302684932@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://l0x1c.github.io/" title="L0x1c" target="_blank">L0x1c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://15h3na0.xyz/" title="15h3na0" target="_blank">15h3na0</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://p3rh4ps.top/" title="p3rh4ps" target="_blank">p3rh4ps</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/yesec/" title="yesec" target="_blank">yesec</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://ch4ser-go.github.io/" title="ch4ser" target="_blank">ch4ser</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.ggb0n.cool/" title="ggb0n" target="_blank">ggb0n</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://github.mrkaixin.computer/" title="mrkaixin" target="_blank">mrkaixin</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://imagin.vip/" title="imagin" target="_blank">imagin</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Python3基础语法"><span class="nav-number">1.</span> <span class="nav-text">Python3基础语法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#编码"><span class="nav-number">1.1.</span> <span class="nav-text">编码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#标识符"><span class="nav-number">1.2.</span> <span class="nav-text">标识符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#python保留字"><span class="nav-number">1.3.</span> <span class="nav-text">python保留字</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注释"><span class="nav-number">1.4.</span> <span class="nav-text">注释</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#为单行注释"><span class="nav-number">2.</span> <span class="nav-text">为单行注释</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#行与缩进"><span class="nav-number">2.1.</span> <span class="nav-text">行与缩进</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多行语句"><span class="nav-number">2.2.</span> <span class="nav-text">多行语句</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数据类型"><span class="nav-number">2.3.</span> <span class="nav-text">数据类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#字符串"><span class="nav-number">2.4.</span> <span class="nav-text">字符串</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#访问字符串中的值"><span class="nav-number">2.4.1.</span> <span class="nav-text">访问字符串中的值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字符串更新"><span class="nav-number">2.4.2.</span> <span class="nav-text">字符串更新</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字符串运算符"><span class="nav-number">2.4.3.</span> <span class="nav-text">字符串运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#三引号"><span class="nav-number">2.4.4.</span> <span class="nav-text">三引号</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常用字符串函数"><span class="nav-number">2.4.5.</span> <span class="nav-text">常用字符串函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#列表"><span class="nav-number">2.5.</span> <span class="nav-text">列表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#访问列表中的值"><span class="nav-number">2.5.1.</span> <span class="nav-text">访问列表中的值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除列表元素"><span class="nav-number">2.5.2.</span> <span class="nav-text">删除列表元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列表脚本操作符"><span class="nav-number">2.5.3.</span> <span class="nav-text">列表脚本操作符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列表常用函数"><span class="nav-number">2.5.4.</span> <span class="nav-text">列表常用函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列表常用方法"><span class="nav-number">2.5.5.</span> <span class="nav-text">列表常用方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#元组"><span class="nav-number">2.6.</span> <span class="nav-text">元组</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#访问元组"><span class="nav-number">2.6.1.</span> <span class="nav-text">访问元组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除元组"><span class="nav-number">2.6.2.</span> <span class="nav-text">删除元组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#元组运算符"><span class="nav-number">2.6.3.</span> <span class="nav-text">元组运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#元组常用函数"><span class="nav-number">2.6.4.</span> <span class="nav-text">元组常用函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#字典"><span class="nav-number">2.7.</span> <span class="nav-text">字典</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#访问字典里的值"><span class="nav-number">2.7.1.</span> <span class="nav-text">访问字典里的值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除字典元素"><span class="nav-number">2.7.2.</span> <span class="nav-text">删除字典元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字典键的特性"><span class="nav-number">2.7.3.</span> <span class="nav-text">字典键的特性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字典常用函数"><span class="nav-number">2.7.4.</span> <span class="nav-text">字典常用函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字典常用方法"><span class="nav-number">2.7.5.</span> <span class="nav-text">字典常用方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#用户输入"><span class="nav-number">2.8.</span> <span class="nav-text">用户输入</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#同一行显示多条语句"><span class="nav-number">2.9.</span> <span class="nav-text">同一行显示多条语句</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多个语句构成代码组"><span class="nav-number">2.10.</span> <span class="nav-text">多个语句构成代码组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#print-输出"><span class="nav-number">2.11.</span> <span class="nav-text">print 输出</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#import与from…import"><span class="nav-number">2.12.</span> <span class="nav-text">import与from…import</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#命令行参数"><span class="nav-number">2.13.</span> <span class="nav-text">命令行参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#运算符"><span class="nav-number">2.14.</span> <span class="nav-text">运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#算数运算符"><span class="nav-number">2.14.1.</span> <span class="nav-text">算数运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#比较运算符"><span class="nav-number">2.14.2.</span> <span class="nav-text">比较运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#赋值运算符"><span class="nav-number">2.14.3.</span> <span class="nav-text">赋值运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#位运算符"><span class="nav-number">2.14.4.</span> <span class="nav-text">位运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#逻辑运算符"><span class="nav-number">2.14.5.</span> <span class="nav-text">逻辑运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#成员运算符"><span class="nav-number">2.14.6.</span> <span class="nav-text">成员运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#身份运算符"><span class="nav-number">2.14.7.</span> <span class="nav-text">身份运算符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常用数学函数"><span class="nav-number">2.14.8.</span> <span class="nav-text">常用数学函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常用随机数函数"><span class="nav-number">2.14.9.</span> <span class="nav-text">常用随机数函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数学常量"><span class="nav-number">2.14.10.</span> <span class="nav-text">数学常量</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#周报总结："><span class="nav-number">2.15.</span> <span class="nav-text">周报总结：</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">51nd0re1</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  
  


  

  

  
  <!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>

</body>
</html>
